<template>
  <div class="app-container">
      <div class="filter-container">
        <el-button class="filter-item" type="primary" v-waves icon="el-icon-plus" @click="handleUpdate(null)">添加</el-button>        
        

        <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
        <el-button class="filter-item" type="primary"  v-waves icon="el-icon-document" @click="exportExcelFile">导出</el-button>
      </div>
      <el-table :data="list" @sort-change="sortChange" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row
      style="width: 100%">
        <el-table-column align="center" type="index" label="序号" width="80">
        </el-table-column>

        
        
        <el-table-column  prop="orderNo" align="center" label="订单号" width="120">
          <template slot-scope="scope">
            <span>{{scope.row.orderNo}}</span>
          </template>
        </el-table-column>
        
        
        <el-table-column  prop="userName" align="center" label="会员名" width="120">
          <template slot-scope="scope">
            <span>{{scope.row.userName}}</span>
          </template>
        </el-table-column>
        
        
        <el-table-column  prop="createTime" align="center" label="申请时间" width="120">
          <template slot-scope="scope">
            <span>{{scope.row.createTime}}</span>
          </template>
        </el-table-column>
        
        
        <el-table-column width="100"  prop="status" align="center" label="处理状态">
          <template slot-scope="scope">
              <el-tag :type="scope.row.status | statustagFilter">{{scope.row.status|statusFilter}}</el-tag>
          </template>
        </el-table-column>
        
        
        <el-table-column  prop="handerTime" align="center" label="处理时间" width="120">
          <template slot-scope="scope">
            <span>{{scope.row.handerTime}}</span>
          </template>
        </el-table-column>
        
        
        <el-table-column align="center" label="操作" width="200" class-name="small-padding">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">修改</el-button>          
            <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="params.page"
        :page-sizes="[10,20,30,50]" :page-size="params.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>

    <el-dialog :title="isEditing?'修改':'添加'" :visible.sync="dialogFormVisible">
      <el-form class="dialog-form" :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="120px">
        
        <el-form-item label="订单号" prop="orderNo">          
            
                                  
                  <el-input v-model="temp.orderNo" placeholder="订单号"></el-input>
                
            
        </el-form-item>         
        
        <el-form-item label="会员名" prop="userId">          
            
                
                  <el-select v-model="temp.userId" placeholder="请选择">
                    <el-option
                      v-for="item in userIdOptions"
                      :key="item.value"
                      :label="item.text"
                      :value="item.value">
                    </el-option>
                  </el-select>
                
            
        </el-form-item>         
        
        <el-form-item label="处理状态" prop="status">          
            
                                  
                  <el-select v-model="temp.status" placeholder="请选择">
                    <el-option
                      v-for="(item,value) in statusFilter"
                      :key="value"
                      :label="item"
                      :value="value">
                    </el-option>
                  </el-select>
                
            
        </el-form-item>         
                         
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" :loading="submiting" @click="submitFormAction">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

let statusFilter = "申请中";
let statustagFilter = ["success", "danger","info","warning"];

export default {
  data() {
    return {
      temp:{
          
          id:'',
          
          orderNo:'',
          
          userId:'',
          
          status:'',
          
      },
      
            userIdOptions:[],
            
            statusFilter:statusFilter,
            
      rules: {
        
        orderNo: [
          
          { required: true, message: "订单号不能为空", trigger: "change"}
          
        ],        
        
        userId: [
          
          { required: true, message: "会员名不能为空", trigger: "change"}
          
        ],        
        
        status: [
          
          { required: true, message: "处理状态不能为空", trigger: "change"}
          
        ],        
        
      }
    };
  },
  created() {
    this.init("exchange_goods",1).loadData();

    
    this.combOptions('user').then(info=>{
        this.userIdOptions = info;
    });
          

    
  },
  filters: {

    statusFilter(status){
        return statusFilter[parseInt(status)];
    },
    statustagFilter(status){
        return statustagFilter[parseInt(status)];
    },

  },
  methods: {
    exportExcelFile() {
      this.exportExcel({
        title: "换货申请单",
        fields: [
          
            
            {field:'orderNo',title:'订单号'}
          
            ,
            {field:'userName',title:'会员名'}
          
            ,
            {field:'createTime',title:'申请时间'}
          
            ,
            {field:'status',title:'处理状态',valueMap:"申请中"}
          
            ,
            {field:'handerTime',title:'处理时间'}
          
        ]
      }).then(info => {
        this.openWin(info);        
      });
    }
  }
};
</script>
